import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:provide/provide.dart';
import 'package:uitest/page/cart_page/cart_bottom.dart';
import 'package:uitest/page/cart_page/cart_item.dart';
import 'package:uitest/provide/cart.dart';

class CartPage extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("购物车"),
      ),
      body: FutureBuilder(
        future: _getCarInfo(context),
        builder: (context,snapshot){
          if (snapshot.hasData) {
            List cartList = Provide.value<CartProvide>(context).cartList;
            return Stack(
                  children: <Widget>[
                    Provide<CartProvide>(
                      builder: (context,child,childCategory){
                        cartList = Provide.value<CartProvide>(context).cartList;
                        return ListView.builder(
                          itemCount: cartList.length,
                          itemBuilder: (context,index){
                            return CartItem(cartList[index]);
                          },
                        );
                      },
                    ),
                    Positioned(
                      bottom:0,
                      left: 0,
                      child: CarBottom(),
                    ),
                  ],
                );
          } else {
            return Text('正在加载');
          }           
        },
      ),
    );
  }

   Future<String> _getCarInfo(BuildContext context) async {
     await Provide.value<CartProvide>(context).getCartInfo();
     return'end';
   }
}